package com.fzhucc.modules.lesson.rest;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.lesson.domain.dto.LessonRecordQueryCriteria;
import com.fzhucc.modules.lesson.service.LessonRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2022-12-07
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "课程:购买记录管理")
@RequestMapping("/api/lessonRecord")
public class LessonRecordController {

    private final LessonRecordService lessonRecordService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('lessonRecord:list')")
    public void exportLessonRecord(HttpServletResponse response, LessonRecordQueryCriteria criteria) throws IOException {
        lessonRecordService.download(lessonRecordService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询lessonRecord")
    @ApiOperation("查询lessonRecord")
    @PreAuthorize("@el.check('lessonRecord:list')")
    public ResponseEntity<Object> queryLessonRecord(LessonRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(lessonRecordService.queryAll(criteria,pageable),HttpStatus.OK);
    }

}